<template>
  <el-select-v2
    v-model="value"
    :options="supplieOptions"
    v-bind="$attrs"
    placeholder="请选择"
    clearable
    filterable
    @change="change"
  >
  </el-select-v2>
</template>
<script setup>
import useCommonStore from "@/store/modules/common";

const commonStore = useCommonStore();
const supplieOptions = computed(() => {
  if (!commonStore.supplieOptions) {
    commonStore.getSupplieList();
  }
  return commonStore.supplieOptions || [];
});

const props = defineProps({
  modelValue: [String, Number, Array],
});

const value = computed(() => {
  return props.modelValue;
});

const emit = defineEmits(["update:modelValue"]);
const change = (val) => {
  const item = supplieOptions.value.find((i) => i.value == val);
  emit("change", item?.label || "");
  emit("changeItem", item || "");
  emit("update:modelValue", val);
};
</script>
